﻿namespace A2DFramework.OSGI.BundleContexts
{
    using System;

    public class RuntimeContext : BundleContext
    {
        private static RuntimeContext instance;

        public RuntimeContext(string moduleName)
        {
            base.Name = moduleName;
        }

        public static RuntimeContext Current
        {
            get
            {
                if (instance == null)
                {
                    if (AppDomain.CurrentDomain.IsDefaultAppDomain())
                    {
                        instance = new RuntimeContext(AppDomain.CurrentDomain.FriendlyName);
                    }
                    else
                    {
                        instance = new RuntimeContext(BundleContext.GetRuntime().GetGlobalProcessor().InAppDomainName);
                    }
                }
                return instance;
            }
        }
    }
}

